<?php

namespace Kylinlxl\QiniuOss;

use Encore\Admin\Admin;
use Encore\Admin\Form;
use Illuminate\Support\ServiceProvider;

class QiniuOssServiceProvider extends ServiceProvider
{
    /**
     * {@inheritdoc}
     */
    public function boot(QiniuOss $extension)
    {
        if (! QiniuOss::boot()) {
            return ;
        }

        if ($views = $extension->views()) {
            $this->loadViewsFrom($views, 'qiniu-oss');
        }

        if ($this->app->runningInConsole() && $assets = $extension->assets()) {
            $this->publishes([$assets => public_path('vendor/kylinlxl/qiniu-oss')], 'qiniu-oss');
            $this->publishes([$extension->config => config_path('qiniu-oss.php')], 'qiniu-oss');
        }

        Admin::booting(function () {
            Form::extend('ossVideo', OssVideo::class);
            Form::extend('ossImage', OssImage::class);
            Form::extend('ossImages', OssImages::class);
            Form::extend('ossWangEditor', OssWangEditor::class);
            Form::extend('ossSimditor', OssSimditor::class);
        });


        $this->app->booted(function () {
            QiniuOss::routes(__DIR__.'/../routes/web.php');
        });
    }
}